/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ibm.law.domain;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.ManyToAny;

/**
 * 
 * @author shanch
 */
@Entity
@Table(name = "document", catalog = "law", schema = "")
@NamedQueries({
		@NamedQuery(name = "Document.findAll", query = "SELECT d FROM Document d"),
		@NamedQuery(name = "Document.findById", query = "SELECT d FROM Document d WHERE d.id = :id"),
		@NamedQuery(name = "Document.findByName", query = "SELECT d FROM Document d WHERE d.name = :name"),
		@NamedQuery(name = "Document.findByShortName", query = "SELECT d FROM Document d WHERE d.shortName = :shortName")/*,
		@NamedQuery(name = "Document.findByCategory", query = "SELECT d FROM Document d WHERE d.category = :category") */
		})
public class Document extends AbstractModelObject implements Serializable {
	@Transient
	private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
			this);
	private static final long serialVersionUID = 1L;
	@Id
	@Basic(optional = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private Long id;
	@Column(name = "name")
	private String name;
	@Column(name = "short_name")
	private String shortName;
	@ManyToMany(mappedBy="documents")
	private List<Category> categories;
//	@ManyToOne
//	@JoinColumn(name = "category_id")
//	private Category category;

	public List<Category> getCategories() {
		return categories;
	}

	public void setCategories(List<Category> categories) {
		this.categories = categories;
	}

	public Document() {
	}

	public Document(Long id) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		Long oldId = this.id;
		this.id = id;
		changeSupport.firePropertyChange("id", oldId, id);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		String oldName = this.name;
		this.name = name;
		changeSupport.firePropertyChange("name", oldName, name);
	}

	public String getShortName() {
		return shortName;
	}

	public void setShortName(String shortName) {
		String oldShortName = this.shortName;
		this.shortName = shortName;
		changeSupport.firePropertyChange("shortName", oldShortName, shortName);
	}

//	public Category getCategory() {
//		return category;
//	}
//
//	public void setCategory(Category category) {
//		this.category = category;
//	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are
		// not set
		if (!(object instanceof Document)) {
			return false;
		}
		Document other = (Document) object;
		if ((this.id == null && other.id != null)
				|| (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "com.ibm.law.entity.Document[ id=" + id + " ]";
	}

	public void addPropertyChangeListener(PropertyChangeListener listener) {
		changeSupport.addPropertyChangeListener(listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener listener) {
		changeSupport.removePropertyChangeListener(listener);
	}

}
